package com.yenlien.traceyun.plant.utils;

import net.sourceforge.pinyin4j.PinyinHelper;

/**
 * @author ChenXi
 * @date 2023/7/5
 */
public class CommonUtils {
    /**
     * 获取文字拼音首字母大写并返回
     * @param chineseCharacter
     * @return
     */
    public static String getPinyinInitials(String chineseCharacter) {
        StringBuilder initials = new StringBuilder();
        for (char c : chineseCharacter.toCharArray()) {
            String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(c);
            if (pinyinArray != null && pinyinArray.length > 0) {
                String pinyin = pinyinArray[0];
                initials.append(Character.toUpperCase(pinyin.charAt(0)));
            }
        }
        return initials.toString();
    }
}
